package com.iot.ht.controller.htrole;

import com.iot.core.annotation.Auth;
import com.iot.core.annotation.Log;
import com.iot.core.data.BasePageDtQto;
import com.iot.core.data.BaseQto;
import com.iot.core.data.IdNameDto;
import com.iot.core.enums.AuthType;
import com.iot.ht.controller.htrole.data.HtRoleDto;
import com.iot.ht.controller.htrole.service.IHtRoleService;
import com.mybatisflex.core.paginate.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/htrole")
@Tag(name = "角色管理", description = "")
public class HtRoleController {
    @Autowired
    IHtRoleService ihtRoleService;

    @Auth(authType = AuthType.Login)
    @Log(logNeed = false,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/page")
    @Operation(summary = "操作日志分页", description = "")
    public Page<HtRoleDto> page(@RequestBody BasePageDtQto qm) throws Exception {

        var r=ihtRoleService.page(  qm );
        return r;
    }

    @Auth(authType = AuthType.Login)
    @Log(logNeed = false,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/detail")
    @Operation(summary = "角色详情", description = "")
    public HtRoleDto detail(@RequestBody BaseQto mm){
        return ihtRoleService.detail(mm);
    }


    @Auth(authType = AuthType.Login)
    @Log(logNeed = false,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/insertinit")
    @Operation(summary = "插入角色初始化", description = "")
    public HtRoleDto insertInit( )   {
         return  ihtRoleService.insertInit();
    }





    @Auth(authType = AuthType.Auth)
    @Log(logNeed = true,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/insert")
    @Operation(summary = "新增角色", description = "")
    public  int insert(@RequestBody HtRoleDto mm){
        return ihtRoleService.insert(mm);
    }


    @Auth(authType = AuthType.Auth)
    @Log(logNeed = true,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/update")
    @Operation(summary = "修改角色", description = "")
    public  int update(@RequestBody HtRoleDto mm){
        return ihtRoleService.update(mm);
    }


    @Auth(authType = AuthType.Auth)
    @Log(logNeed = true,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/delete")
    @Operation(summary = "删除角色", description = "")
    public  int delete(@RequestBody BaseQto mm){
        return ihtRoleService.delete(mm);
    }




    @Auth(authType = AuthType.Login)
    @Log(logNeed = false,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/listbydeptid")
    @Operation(summary = "根据部门获取角色", description = "")
    public List<IdNameDto> listByDeptId(@RequestBody BaseQto mm){
        return ihtRoleService.listByDeptId(mm  );
    }




}
